/ Assembly List / LJCDBClientLib / DataManager / Add

Namespace - LJCDBClientLib


Parameters
dataObject - The record object.
propertyNames - The included column property names.
includeNull - Includes columns with null value.

Returns

The result object.

Syntax

C#
public DbResult Add(Object dataObject, List<String> propertyNames = null, Boolean includeNull = False)

Adds a record to the database. (RE)

Remarks

Parameters

propertyNames
This parameter defines the primary table column values that are to be added. If it is null, then all the primary table column values are added.
It must not include Calculated or Join columns or it will cause an error.

Creates an "Insert" DbRequest object. The DbRequest.Columns object includes the definitions for the columns to be updated in the base table.

The DbRequest.Columns include all columns from the BaseDefinition by default; except it does not include AutoIncrement columns or columns with null values. To include a null column value, set the column value to "-null". It only includes the columns contained in the optional propertyNames parameter if provided. It uses the columns in the ChangedNames object if it exists and the propertyNames parameter is null.

The DbRequest.Columns do not include AutoIncrement columns or columns with null values. To include a null column value, set the column value to "-null".

The Key Columns are assigned from the LookupColumnNames property. The keyColumn.ColumnName must be available in the BaseDefinition object to be included.

The Key Columns are those columns whose value will be used to find the added record. This is to return the DB Assigned column values to the calling program.

The keyColumns do not use keys with null values or invalid dates. To include a null column value, set the column value to "'-null'".

Verify: The Key Columns must include the DB Assigned columns for the assigned values to be returned to the calling program. The value must be set to zero to prevent including it as a key value?

Verify: The Lookup Retrieve call will not include keys with a value of "0".

Verify: The Add Data Object property names must be the same as the Request Column property names to map the values into the Key Columns.

Method Graph

All methods are in LJCDBMessage.DbCommon.

RequestDataColumns(dataObject)
RequestColumns(baseDefinition)
DataColumns(dataObject)
CreateValueColumn(dbColumn)
RequestLookupKeys(dataObject)
RequestColumns(baseDefinition)
LookupKeys(dataObject)
IsKeyColumn(dbColumn)

Example

C#
// This is an example of the Person Manager code that would access the
// DataManager Add() method. The supporting class code is listed at the
// DataManager class level.
    
using LJCNetCommon;
using LJCDBMessage;
    
<span class='xmlComment'>/// <summary>Provides Person specific data manipulation methods.</summary></span>
public class PersonManager
{
    <span class='xmlComment'>/// <summary>Adds a person record to the database.</summary></span>
    /// <param name="dataObject">The data record.</param>
    /// <param name="propertyNames">The included column property names.</param>
    <span class='xmlComment'>/// <returns>A person object with the DB assigned key values.</returns></span>
    public Person Add(Person dataObject, List<string> propertyNames = null)
    {
        Person retValue = null;
    
        // The database assigned column names.
        mDataManager.SetDbAssignedColumnNames(new string[]
        {
            "Id"
        });
    
        // The lookup column names to find the inserted record for
        // the Add() method to retrieve the DB assigned column values.
        mDataManager.AddLookupColumnNames(new string[]
        {
            "Name"
        });
    
        DbResult dbResult = mDataManager.Add(dataObject, propertyNames);
        AffectedCount = mDataManager.AffectedCount;
        SQLStatement = mDataManager.SQLStatement;
        if (dbResult != null && dbResult.DbRecords.Count > 0)
        {
            // Populate a data object with the result values.
            retValue = new Person();
            DbCommon.SetObjectValues(dbResult.DbRecords[0], retValue);
        }
    
        int personId = retValue.PersonId;
        return retValue;
    }
}

Copyright © Lester J. Clark and Contributors.
Licensed under the MIT License.